package cn.com.callback;

import cn.com.elite.EliteBean;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * @Title: autoJyStandardTask*
 * @Description: 1. 同步客户资料到Customer表 ,2. 工作日同步各类经营任务到account_information表
 * @author: th @date 2022-5-28 14:00:00
 */
public class autoJyStandardTask implements CallBackInvoke {
    // 日志对象
    private static final Log log = LogFactory.getLog(autoJyStandardTask.class);

    // ==================== 客户资料同步SQL常量 ====================
    /**
     * 首次同步客户资料SQL（通过手机号匹配，针对未设置Customer_Id的客户）
     */
    private static final String CUSTOMER_SYNC_BY_MOBILE_SQL = """
        UPDATE Customer R1, Dws.Paqh_Userinfo R2
           SET R1.Customername         = R2.Investorname,
               R1.Customer_Id          = R2.Investorid,
               R1.Idtype               = R2.Identifiedcardtype,
               R1.Customerid           = R2.Identifiedcardno,
               R1.Valid_Documents_Date = R2.Idcardvalidityend,
               R1.Gender               = R2.Sex,
               R1.Customertype2_Id     = R2.Investortype,
               R1.Address              = R2.Address,
               R1.Mobile               = R2.Mobile,
               R1.Evaluate             = R2.Riskbearingcapacity,
               R1.Customer_State       = R2.freezestatus,
               R1.Account_State        = R2.Isactive,
               R1.Open_Account         = R2.Opendate,
               R1.Register_Time        = R2.f_Register_Time,
               R1.Recommend            = R2.f_Referee_No,
               R1.Recommend_Name       = R2.f_Referee_Naem,
               R1.Peak_Value_Qy        = R2.Max_End_Rights,
               R1.Opengz               = R2.Opengz,
               R1.Openyy               = R2.Openyy,
               R1.Open20hj             = R2.Open20hj,
               R1.Ifopeni              = R2.Ifopeni,
               R1.Ifopenta             = R2.Ifopenta,
               R1.Openqq               = R2.Openqq,
               R1.Opendinedate         = R2.Opendinedate,
               R1.Opendlrly            = R2.Opendlrly,
               R1.Opengjt              = R2.Opengjt,
               R1.Openzly              = R2.Openzly,
               R1.channel              = R2.f_channel,
               R1.f_Xf_Channel         = R2.f_Xf_Channel,
               R1.departmentid         = R2.Departmentid,
               R1.departmentname       = R2.Departmentname,
               R1.intermediary         = R2.f_ywry_code,
               R1.first_rj_time        = R2.fundinday,
               R1.first_jy_time        = R2.firstday,
               R1.end_jy_time          = R2.lastday,
               R1.handling_fee         = R2.commmodelname,
               R1.margin               = R2.marginmodelname,
               R1.memo                 = R2.memo,
               R1.sum_day              = R2.sum_day,
               R1.sum_number           = R2.sum_number,
               R1.MODIFIEDBY           = '000116',
               R1.MODIFIEDDATE         = now(),
               R1.canceldate           = R2.canceldate,
               R1.province             = R2.province,
               R1.city                 = R2.city,
               R1.dridentityid         = R2.dridentityid,
               R1.validity_date        = R2.validity_date
         WHERE R1.Mobile = R2.Mobile
           AND (R1.Customer_Id IS NULL OR R1.Customer_Id = '')
        """;

    /**
     * 二次同步客户资料SQL（通过资金账号匹配）
     */
    private static final String CUSTOMER_SYNC_BY_FUND_ID_SQL = """
        UPDATE Customer R1, Dws.Paqh_Userinfo R2
           SET R1.Customername         = R2.Investorname,
               R1.Idtype               = R2.Identifiedcardtype,
               R1.Customerid           = R2.Identifiedcardno,
               R1.Valid_Documents_Date = R2.Idcardvalidityend,
               R1.Gender               = R2.Sex,
               R1.Customertype2_Id     = R2.Investortype,
               R1.Address              = R2.Address,
               R1.Mobile               = R2.Mobile,
               R1.Evaluate             = R2.Riskbearingcapacity,
               R1.Customer_State       = R2.freezestatus,
               R1.Account_State        = R2.Isactive,
               R1.Open_Account         = R2.Opendate,
               R1.Register_Time        = R2.f_Register_Time,
               R1.Recommend            = R2.f_Referee_No,
               R1.Recommend_Name       = R2.f_Referee_Naem,
               R1.Peak_Value_Qy        = R2.Max_End_Rights,
               R1.Opengz               = R2.Opengz,
               R1.Openyy               = R2.Openyy,
               R1.Open20hj             = R2.Open20hj,
               R1.Ifopeni              = R2.Ifopeni,
               R1.Ifopenta             = R2.Ifopenta,
               R1.Openqq               = R2.Openqq,
               R1.Opendinedate         = R2.Opendinedate,
               R1.Opendlrly            = R2.Opendlrly,
               R1.Opengjt              = R2.Opengjt,
               R1.Openzly              = R2.Openzly,
               R1.channel              = R2.f_channel,
               R1.f_Xf_Channel         = R2.f_Xf_Channel,
               R1.departmentid         = R2.Departmentid,
               R1.departmentname       = R2.Departmentname,
               R1.intermediary         = R2.f_ywry_code,
               R1.first_rj_time        = R2.fundinday,
               R1.first_jy_time        = R2.firstday,
               R1.end_jy_time          = R2.lastday,
               R1.handling_fee         = R2.commmodelname,
               R1.margin               = R2.marginmodelname,
               R1.memo                 = R2.memo,
               R1.sum_day              = R2.sum_day,
               R1.sum_number           = R2.sum_number,
               R1.MODIFIEDBY           = '000116',
               R1.MODIFIEDDATE         = now(),
               R1.canceldate           = R2.canceldate,
               R1.province             = R2.province,
               R1.city                 = R2.city,
               R1.dridentityid         = R2.dridentityid,
               R1.validity_date        = R2.validity_date
         WHERE R1.Customer_Id = R2.Investorid
        """;

    /**
     * 节假日校验SQL（查询当前日期是否为工作日）
     */
    private static final String HOLIDAY_CHECK_SQL = """
        SELECT R1.Freedate, R1.datetype, R1.Next_Freedate, 
               Datediff(R1.Next_Freedate, R1.Freedate) As Datediff 
          FROM (SELECT R0.d_Date As Freedate, 
                       R1.Datetype, 
                       Min(Date_Format(R2.Freedate, '%Y-%m-%d')) As Next_Freedate 
                  FROM Dim_d_Day R0 
                  LEFT JOIN c_Freedate R1 
                    ON R0.d_Date = Date_Format(R1.Freedate,'%Y-%m-%d') 
                   AND R1.Datetype In ('PA0001', 'PA0000') 
                  LEFT JOIN c_Freedate R2 
                    ON R1.Freedate < R2.Freedate 
                   AND R2.Datetype = 'PA0001' 
                 WHERE R0.d_Date = Date_Format(Now(), '%Y-%m-%d') 
                 GROUP BY Date_Format(R1.Freedate, '%Y-%m-%d'), R0.d_Date, R1.Datetype
               ) R1
        """;

    // ==================== 经营任务同步SQL常量 ====================
    /**
     * 客户信息更新SQL（针对电销外呼任务未处理的客户）
     */
    private static final String CUSTOMER_UPDATE_FOR_CALL_TASK_SQL = """
        UPDATE Customer R1, 
               (SELECT pu.* 
                  FROM account_information k1 
                  INNER JOIN dws.paqh_userinfo pu 
                    ON k1.customerid = pu.investorid 
                 WHERE k1.task_type IN (SELECT code_id FROM c_codetables WHERE use_type = '电销外呼类型') 
                   AND k1.deal_flag = '-2' 
                   AND k1.createtime >= DATE_FORMAT(now(),'%Y-%m-%d 00:00:00')
               ) R2 
           SET R1.Customername         = R2.Investorname,
               R1.Customer_Id          = R2.Investorid,
               R1.Idtype               = R2.Identifiedcardtype,
               R1.Customerid           = R2.Identifiedcardno,
               R1.Valid_Documents_Date = R2.Idcardvalidityend,
               R1.Gender               = R2.Sex,
               R1.Customertype2_Id     = R2.Investortype,
               R1.Address              = R2.Address,
               R1.Mobile               = R2.Mobile,
               R1.Evaluate             = R2.Riskbearingcapacity,
               R1.Customer_State       = R2.freezestatus,
               R1.Account_State        = R2.Isactive,
               R1.Open_Account         = R2.Opendate,
               R1.Register_Time        = R2.f_Register_Time,
               R1.Recommend            = R2.f_Referee_No,
               R1.Recommend_Name       = R2.f_Referee_Naem,
               R1.Peak_Value_Qy        = R2.Max_End_Rights,
               R1.Opengz               = R2.Opengz,
               R1.Openyy               = R2.Openyy,
               R1.Open20hj             = R2.Open20hj,
               R1.Ifopeni              = R2.Ifopeni,
               R1.Ifopenta             = R2.Ifopenta,
               R1.Openqq               = R2.Openqq,
               R1.Opendinedate         = R2.Opendinedate,
               R1.Opendlrly            = R2.Opendlrly,
               R1.Opengjt              = R2.Opengjt,
               R1.Openzly              = R2.Openzly,
               R1.channel              = R2.f_channel,
               R1.f_Xf_Channel         = R2.f_Xf_Channel,
               R1.departmentid         = R2.Departmentid,
               R1.departmentname       = R2.Departmentname,
               R1.intermediary         = R2.f_ywry_code,
               R1.first_rj_time        = R2.fundinday,
               R1.first_jy_time        = R2.firstday,
               R1.end_jy_time          = R2.lastday,
               R1.handling_fee         = R2.commmodelname,
               R1.margin               = R2.marginmodelname,
               R1.memo                 = R2.memo,
               R1.sum_day              = R2.sum_day,
               R1.sum_number           = R2.sum_number,
               R1.MODIFIEDBY           = '000258',
               R1.MODIFIEDDATE         = now(),
               R1.canceldate           = R2.canceldate,
               R1.province             = R2.province,
               R1.city                 = R2.city 
         WHERE R1.Mobile = R2.Mobile 
           AND (R1.Customer_Id IS NULL OR R1.Customer_Id = '')
        """;

    /**
     * 新增客户信息SQL（针对电销外呼任务未处理的客户）
     */
    private static final String CUSTOMER_INSERT_FOR_CALL_TASK_SQL = """
        INSERT INTO Customer(
            Customer_Guid, Customer_Id, Customername, Idtype, Customerid, 
            Valid_Documents_Date, Gender, Customertype2_Id, Address, Mobile, 
            Evaluate, Customer_State, Account_State, Open_Account, Register_Time, 
            Recommend, Recommend_Name, f_Xf_Channel, Peak_Value_Qy, Opengz, 
            Openyy, Open20hj, Ifopeni, Ifopenta, Openqq, Opendinedate, 
            Opendlrly, Opengjt, Openzly, Channel, departmentid, departmentname, 
            intermediary, first_rj_time, first_jy_time, end_jy_time, handling_fee, 
            margin, memo, sum_day, sum_number, CREATEDBY, CREATEDDATE, canceldate, 
            province, city
        ) 
        SELECT DISTINCT 
            Concat(Substr('PA-CUSTOMER-########################', 1, 36 - Length(R1.Investorid)), R1.Investorid) As Customer_Guid,
            R1.Investorid, R1.Investorname, R1.Identifiedcardtype, R1.Identifiedcardno,
            R1.Idcardvalidityend, R1.Sex, R1.Investortype, R1.Address, R1.Mobile,
            R1.Riskbearingcapacity, R1.freezestatus, R1.Isactive, R1.Opendate, R1.f_Register_Time,
            R1.f_Referee_No, R1.f_Referee_Naem, R1.f_Xf_Channel, R1.Max_End_Rights, R1.Opengz,
            R1.Openyy, R1.Open20hj, R1.Ifopeni, R1.Ifopenta, R1.Openqq, R1.Opendinedate,
            R1.Opendlrly, R1.Opengjt, R1.Openzly, R1.f_channel, R1.Departmentid, R1.Departmentname,
            R1.f_ywry_code, R1.fundinday, R1.firstday, R1.lastday, R1.commmodelname,
            R1.marginmodelname, R1.memo, R1.sum_day, R1.sum_number, '000258', now(),
            R1.canceldate, R1.province, R1.city 
          FROM Dws.Paqh_Userinfo R1 
          LEFT JOIN Customer R2 
            ON R1.Investorid = R2.Customer_Id 
         WHERE (R2.Customer_Guid IS NULL OR R2.Customer_Id = '') 
           AND R1.investorid IN (
               SELECT customerid 
                 FROM account_information 
                WHERE task_type IN (SELECT code_id FROM c_codetables WHERE use_type = '电销外呼类型') 
                  AND deal_flag = '-2' 
                  AND createtime >= DATE_FORMAT(now(),'%Y-%m-%d 00:00:00')
           )
        """;

    /**
     * 开户任务同步SQL
     */
    private static final String OPEN_ACCOUNT_TASK_SQL = """
        INSERT INTO account_information(
            rec_id, task_guid, customerid, task_type, source, createtime, deal_flag
        ) 
        SELECT uuid(), uuid(), s.investorid, 'DX_01', '2', now(), '0' 
          FROM dws.openname s 
          LEFT JOIN account_information a 
            ON a.customerid = s.investorid AND a.task_type = 'DX_01' 
         WHERE (a.customerid IS NULL OR a.customerid = '') 
         ORDER BY s.opendate desc
        """;

    /**
     * 首次交易任务同步SQL
     */
    private static final String FIRST_TRADE_TASK_SQL = """
        INSERT INTO account_information(
            rec_id, task_guid, customerid, task_type, source, createtime, deal_flag
        ) 
        SELECT uuid(), uuid(), s.investorid, 'DX_02', '2', now(), '0' 
          FROM dws.z_first_trade_final s 
          LEFT JOIN account_information a 
            ON a.customerid = s.investorid AND a.task_type = 'DX_02' 
         WHERE (a.customerid IS NULL OR a.customerid = '') 
         ORDER BY s.opendate desc
        """;

    /**
     * 上一交易日激活任务同步SQL
     */
    private static final String PREV_ACTIVE_TASK_SQL = """
        INSERT INTO account_information(
            rec_id, task_guid, customerid, task_type, source, createtime, deal_flag, activedate
        ) 
        SELECT uuid(), uuid(), s.investorid, 'DX_03', '2', now(), '0', s.activedate 
          FROM dws.z_active_name s 
          LEFT JOIN account_information a 
            ON a.customerid = s.investorid 
           AND a.activedate = s.activedate 
           AND a.task_type = 'DX_03' 
         WHERE (a.customerid IS NULL OR a.customerid = '') 
           AND DATE_FORMAT(s.activedate,'%Y-%m-%d') > '2022-04-22'
        """;

    /**
     * 股指新开户T-1任务同步SQL
     */
    private static final String STOCK_INDEX_NEW_ACCOUNT_TASK_SQL = """
        INSERT INTO account_information(
            rec_id, task_guid, customerid, task_type, source, createtime, deal_flag
        ) 
        SELECT uuid(), uuid(), s.investorid, 'DX_04', '2', now(), '0' 
          FROM dws.v_mos_gj_cffex_cust s 
          LEFT JOIN account_information a 
            ON a.customerid = s.investorid AND a.task_type = 'DX_04' 
         WHERE (a.customerid IS NULL OR a.customerid = '')
        """;

    /**
     * 近1月未交易任务同步SQL
     */
    private static final String NO_TRADE_1MONTH_TASK_SQL = """
        INSERT INTO account_information(
            rec_id, task_guid, customerid, task_type, source, createtime, deal_flag
        ) 
        SELECT uuid(), uuid(), s.accountid, 'DX_05', '2', now(), '0' 
          FROM dws.z_no_trade_month s 
          LEFT JOIN account_information a 
            ON a.customerid = s.accountid AND a.task_type = 'DX_05' 
         WHERE (a.customerid IS NULL OR a.customerid = '')
        """;

    /**
     * 近3月未交易任务同步SQL
     */
    private static final String NO_TRADE_3MONTH_TASK_SQL = """
        INSERT INTO account_information(
            rec_id, task_guid, customerid, task_type, source, createtime, deal_flag
        ) 
        SELECT uuid(), uuid(), s.accountid, 'DX_06', '2', now(), '0' 
          FROM dws.z_no_trade_half_year s 
          LEFT JOIN account_information a 
            ON a.customerid = s.accountid AND a.task_type = 'DX_06' 
         WHERE (a.customerid IS NULL OR a.customerid = '')
        """;

    /**
     * 近6月未交易任务同步SQL
     */
    private static final String NO_TRADE_6MONTH_TASK_SQL = """
        INSERT INTO account_information(
            rec_id, task_guid, customerid, task_type, source, createtime, deal_flag
        ) 
        SELECT uuid(), uuid(), s.accountid, 'DX_07', '2', now(), '0' 
          FROM dws.z_no_trade_year s 
          LEFT JOIN account_information a 
            ON a.customerid = s.accountid AND a.task_type = 'DX_07' 
         WHERE (a.customerid IS NULL OR a.customerid = '')
        """;

    /**
     * 近1年达标未开原油任务同步SQL
     */
    private static final String NO_CRUDOIL_1YEAR_QUALIFIED_TASK_SQL = """
        INSERT INTO account_information(
            rec_id, task_guid, customerid, task_type, source, createtime, deal_flag
        ) 
        SELECT uuid(), uuid(), s.accountid, 'DX_08', '2', now(), '0' 
          FROM dws.no_opendine_year s 
          LEFT JOIN account_information a 
            ON a.customerid = s.accountid AND a.task_type = 'DX_08' 
         WHERE (a.customerid IS NULL OR a.customerid = '')
        """;

    /**
     * 上日权益50W+未开股指任务同步SQL
     */
    private static final String NO_STOCK_INDEX_50W_TASK_SQL = """
        INSERT INTO account_information(
            rec_id, task_guid, customerid, task_type, source, createtime, deal_flag
        ) 
        SELECT uuid(), uuid(), s.accountid, 'DX_09', '2', now(), '0' 
          FROM dws.no_open_gz s 
          LEFT JOIN account_information a 
            ON a.customerid = s.accountid AND a.task_type = 'DX_09' 
         WHERE (a.customerid IS NULL OR a.customerid = '')
        """;

    /**
     * VIP客户任务同步SQL
     */
    private static final String VIP_CUSTOMER_TASK_SQL = """
        INSERT INTO account_information(
            rec_id, task_guid, customerid, task_type, source, createtime, deal_flag
        ) 
        SELECT uuid(), uuid(), s.accountid, 'DX_10', '2', now(), '0' 
          FROM dws.z_vip_custom s 
          LEFT JOIN account_information a 
            ON a.customerid = s.accountid AND a.task_type = 'DX_10' 
         WHERE (a.customerid IS NULL OR a.customerid = '')
        """;

    /**
     * 休眠客户任务同步SQL
     */
    private static final String DORMANT_CUSTOMER_TASK_SQL = """
        INSERT INTO account_information(
            rec_id, task_guid, customerid, task_type, source, createtime, deal_flag
        ) 
        SELECT uuid(), uuid(), s.investorid, 'DX_11', '2', now(), '0' 
          FROM dws.z_dormancy s 
          LEFT JOIN dws.paqh_userinfo p 
            ON s.investorid = p.investorid 
          LEFT JOIN account_information a 
            ON a.customerid = s.investorid AND a.task_type = 'DX_11' 
         WHERE (a.customerid IS NULL OR a.customerid = '') 
           AND p.opendate >= DATE_FORMAT(subdate(now(), INTERVAL 2 YEAR),'%Y%m%d') 
           AND p.opendate <= DATE_FORMAT(now(),'%Y%m%d') 
         ORDER BY p.opendate desc
        """;

    /**
     * 未绑定银期任务同步SQL
     */
    private static final String NO_BIND_BANK_FUTURE_TASK_SQL = """
        INSERT INTO account_information(
            rec_id, task_guid, customerid, task_type, source, createtime, deal_flag
        ) 
        SELECT uuid(), uuid(), s.investorid, 'DX_12', '2', now(), '0' 
          FROM dws.z_no_bind_yq_year s 
          LEFT JOIN account_information a 
            ON a.customerid = s.investorid AND a.task_type = 'DX_12' 
          LEFT JOIN dws.paqh_userinfo p 
            ON s.investorid = p.investorid 
         WHERE (a.customerid IS NULL OR a.customerid = '') 
           AND TIMESTAMPDIFF(DAY, DATE_FORMAT(p.opendate,'%Y-%m-%d'), DATE_FORMAT(now(),'%Y-%m-%d')) >= 14
        """;

    /**
     * 已绑定银期未入金任务同步SQL
     */
    private static final String BIND_NO_FUNDIN_TASK_SQL = """
        INSERT INTO account_information(
            rec_id, task_guid, customerid, task_type, source, createtime, deal_flag
        ) 
        SELECT uuid(), uuid(), s.investorid, 'DX_15', '2', now(), '0' 
          FROM dws.z_nofundin_bind_yq s 
          LEFT JOIN account_information a 
            ON a.customerid = s.investorid AND a.task_type = 'DX_15' 
          LEFT JOIN dws.paqh_userinfo p 
            ON s.investorid = p.investorid 
         WHERE (a.customerid IS NULL OR a.customerid = '') 
           AND TIMESTAMPDIFF(DAY, DATE_FORMAT(p.opendate,'%Y-%m-%d'), DATE_FORMAT(now(),'%Y-%m-%d')) >= 14
        """;

    /**
     * 已入金未交易任务同步SQL
     */
    private static final String FUNDIN_NO_TRADE_TASK_SQL = """
        INSERT INTO account_information(
            rec_id, task_guid, customerid, task_type, source, createtime, deal_flag
        ) 
        SELECT uuid(), uuid(), s.investorid, 'DX_16', '2', now(), '0' 
          FROM dws.z_no_trade_fundin s 
          LEFT JOIN account_information a 
            ON a.customerid = s.investorid AND a.task_type = 'DX_16' 
          LEFT JOIN dws.paqh_userinfo p 
            ON s.investorid = p.investorid 
         WHERE (a.customerid IS NULL OR a.customerid = '') 
           AND TIMESTAMPDIFF(DAY, DATE_FORMAT(p.opendate,'%Y-%m-%d'), DATE_FORMAT(now(),'%Y-%m-%d')) >= 14
        """;


    @Override
    public void doCallBack(EliteBean eliteBean, String s, Map map, String s1) {
        log.debug("===== 开始执行自动经营标准任务回调 =====");

        // 1. 同步客户资料（分两次：先通过手机号匹配未设置资金账号的客户，再通过资金账号精确匹配）
        syncCustomerInfo(eliteBean);

        // 2. 校验当前是否为工作日，工作日才同步经营任务
        if (isWorkDay(eliteBean)) {
            log.debug("当前为工作日，开始同步经营任务");
            SyncTask(eliteBean);
        } else {
            log.debug("当前为节假日，跳过经营任务同步");
        }

        log.debug("===== 自动经营标准任务回调执行完毕 =====");
    }

    /**
     * 同步客户资料到Customer表
     */
    private void syncCustomerInfo(EliteBean eliteBean) {
        // 1.1 通过手机号同步未设置资金账号的客户
        log.debug("开始通过手机号同步客户资料（未设置Customer_Id的客户）");
        int mobileSyncRowCount = eliteBean.update(CUSTOMER_SYNC_BY_MOBILE_SQL, "dataSource");
        log.debug("通过手机号同步客户资料完成，更新条数：" + mobileSyncRowCount);

        // 1.2 通过资金账号同步客户资料
        log.debug("开始通过资金账号同步客户资料");
        int fundIdSyncRowCount = eliteBean.update(CUSTOMER_SYNC_BY_FUND_ID_SQL, "dataSource");
        log.debug("通过资金账号同步客户资料完成，更新条数：" + fundIdSyncRowCount);
    }

    /**
     * 判断当前是否为工作日
     * @return true-工作日，false-节假日
     */
    private boolean isWorkDay(EliteBean eliteBean) {
        log.debug("开始校验当前日期是否为工作日");
        List<Map> holidayCheckList = eliteBean.chaxun_sql(HOLIDAY_CHECK_SQL, "dataSource");

        if (holidayCheckList.isEmpty()) {
            log.debug("未查询到节假日配置，默认按工作日处理");
            return true;
        }

        Map<String, Object> holidayInfo = holidayCheckList.get(0);
        String dateType = (String) holidayInfo.get("datetype");
        log.debug("节假日校验结果，日期类型：" + dateType);

        // PA0001表示非节假日（工作日）
        return "PA0001".equals(dateType);
    }

    /**
     * 同步经营任务到account_information表（仅工作日执行）
     */
    public static void SyncTask(EliteBean eliteBean) {
        long startTime = System.currentTimeMillis();
        log.debug("===== 开始执行工作日经营任务同步 =====");

        try {
            // 1. 更新电销外呼任务相关客户信息
            log.debug("开始更新电销外呼任务客户信息");
            int callTaskCustomerUpdateCount = eliteBean.update(CUSTOMER_UPDATE_FOR_CALL_TASK_SQL, "dataSource");
            log.debug("电销外呼任务客户信息更新完成，更新条数：" + callTaskCustomerUpdateCount);

            // 2. 新增电销外呼任务相关客户
            log.debug("开始新增电销外呼任务客户信息");
            int newCustomerInsertCount = eliteBean.update(CUSTOMER_INSERT_FOR_CALL_TASK_SQL, "dataSource");
            log.debug("电销外呼任务客户信息新增完成，新增条数：" + newCustomerInsertCount);

            // 3. 同步各类经营任务
            int openAccountTaskCount = eliteBean.update(OPEN_ACCOUNT_TASK_SQL, "dataSource");
            log.debug("开户任务同步完成，新增条数：" + openAccountTaskCount);

            int firstTradeTaskCount = eliteBean.update(FIRST_TRADE_TASK_SQL, "dataSource");
            log.debug("首次交易任务同步完成，新增条数：" + firstTradeTaskCount);

            int prevActiveTaskCount = eliteBean.update(PREV_ACTIVE_TASK_SQL, "dataSource");
            log.debug("上一交易日激活任务同步完成，新增条数：" + prevActiveTaskCount);

            int stockIndexNewAccountCount = eliteBean.update(STOCK_INDEX_NEW_ACCOUNT_TASK_SQL, "dataSource");
            log.debug("股指新开户T-1任务同步完成，新增条数：" + stockIndexNewAccountCount);

            int noTrade1MonthCount = eliteBean.update(NO_TRADE_1MONTH_TASK_SQL, "dataSource");
            log.debug("近1月未交易任务同步完成，新增条数：" + noTrade1MonthCount);

            int noTrade3MonthCount = eliteBean.update(NO_TRADE_3MONTH_TASK_SQL, "dataSource");
            log.debug("近3月未交易任务同步完成，新增条数：" + noTrade3MonthCount);

            int noTrade6MonthCount = eliteBean.update(NO_TRADE_6MONTH_TASK_SQL, "dataSource");
            log.debug("近6月未交易任务同步完成，新增条数：" + noTrade6MonthCount);

            int noCrudeOil1YearCount = eliteBean.update(NO_CRUDOIL_1YEAR_QUALIFIED_TASK_SQL, "dataSource");
            log.debug("近1年达标未开原油任务同步完成，新增条数：" + noCrudeOil1YearCount);

            int noStockIndex50WCount = eliteBean.update(NO_STOCK_INDEX_50W_TASK_SQL, "dataSource");
            log.debug("上日权益50W+未开股指任务同步完成，新增条数：" + noStockIndex50WCount);

            int vipCustomerTaskCount = eliteBean.update(VIP_CUSTOMER_TASK_SQL, "dataSource");
            log.debug("VIP客户任务同步完成，新增条数：" + vipCustomerTaskCount);

            int dormantCustomerTaskCount = eliteBean.update(DORMANT_CUSTOMER_TASK_SQL, "dataSource");
            log.debug("休眠客户任务同步完成，新增条数：" + dormantCustomerTaskCount);

            int noBindBankFutureCount = eliteBean.update(NO_BIND_BANK_FUTURE_TASK_SQL, "dataSource");
            log.debug("未绑定银期任务同步完成，新增条数：" + noBindBankFutureCount);

            int bindNoFundInCount = eliteBean.update(BIND_NO_FUNDIN_TASK_SQL, "dataSource");
            log.debug("已绑定银期未入金任务同步完成，新增条数：" + bindNoFundInCount);

            int fundInNoTradeCount = eliteBean.update(FUNDIN_NO_TRADE_TASK_SQL, "dataSource");
            log.debug("已入金未交易任务同步完成，新增条数：" + fundInNoTradeCount);

        } catch (Exception e) {
            log.error("同步经营任务时发生异常", e);
            return;
        }

        long endTime = System.currentTimeMillis();
        log.debug("===== 工作日经营任务同步完成，处理时长(毫秒)：" + (endTime - startTime) + " =====");
    }
}